package KafkaApps;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class ImgTest {
    public static void imgtest() throws Exception {
        File img = new File("trans_file/producer_file/test.txt");
        System.out.println(img.getName());
        List<byte[]> imgList = new ArrayList<>();

        FileInputStream in = null;
        FileOutputStream fileOutputStream = null;
        in = new FileInputStream(img);
        fileOutputStream = new FileOutputStream("trans_file/producer_file/c.txt");

        // 读入多个字节到字节数组中，byteread为一次读入的字节数
        int end = 0;
        while (true) {
            byte[] tempbytes = new byte[100];

            if (in.read(tempbytes) == -1) break;
            imgList.add(tempbytes);
        }
        for(byte[] bytes:imgList){
            fileOutputStream.write(bytes);
        }
        in.close();
        fileOutputStream.close();

    }
    public static void bytetest(){
        String i = "1";
        System.out.println(i.getBytes());
        System.out.println(new String(i.getBytes()));
    }

    public static void hang() throws IOException {
        FileOutputStream fileOutputStream = null;
        fileOutputStream = new FileOutputStream("trans_file/producer_file/test2.txt");
        String a = null;
        for (int i=1;i<=10000*1000;i++) {
            //System.out.println("这是第"+i+"行");
            a = "这是第" + i + "行\r\n";
            fileOutputStream.write(a.getBytes());
            if (i%10000==0) System.out.println("现在写到了"+i+"行");
        }
    }

    public static void main(String... args) throws Exception {
        imgtest();
    }
}
